package com.zhouwr.protocol;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.zhouwr.common.enums.ProtocolType;
import com.zhouwr.common.network.DeviceMessageCodec;
import io.netty.channel.ChannelHandler;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.LinkedHashMap;

/**
 * @program: forallcn-iotps
 * @description: WIRELESS120的编解码器
 * @author: zhouwr
 * @create: 2020-12-05 13:47
 * @version：1.0
 **/
@Slf4j
@ChannelHandler.Sharable
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})
public class Wireless120Codec implements DeviceMessageCodec, Serializable {
    private static final long serialVersionUID = 1L;

    @Override
    public ProtocolType getProtocolType() {
        return ProtocolType.TCP;
    }

    /**
     * 解码器
     *
     * @return
     */
    @Override
    public LinkedHashMap<String, ChannelHandler> getDecoders() {
        log.info(">>>> ChannelHandler getDecoder()");
        LinkedHashMap<String, ChannelHandler> decoders = new LinkedHashMap<>();
        decoders.put("Wireless120SyncReceiver", new Wireless120SyncReceiver());
        decoders.put("Wireless120Decoder", new Wireless120Decoder());
        return decoders;
    }

    /**
     * 编码器
     *
     * @return
     */
    @Override
    public LinkedHashMap<String, ChannelHandler> getEncoders() {
        log.info(">>>> ChannelHandler getEncoder()");
        LinkedHashMap<String, ChannelHandler> encoders = new LinkedHashMap<>();
        encoders.put("Wireless120Encoder", new Wireless120Encoder());
        return encoders;
    }
}
